package dataClean;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

/**
 * @author Smartloe
 * @create 2021-04-29 19:29
 */
public class TxtCase2
    {
        public static void main(String[] args) throws Exception
        {

            //时间数据提取
            timetransform();
        }

        public static void timetransform() throws FileNotFoundException {
        //step 1 打开文件并且读取内容。
        Scanner file = new Scanner(new File("src\\main\\java\\dataClean\\data\\TxtCase2.txt"));

        ArrayList<String> fileContent = new ArrayList<String>();
        //移除文件中一部分的字符
        String clearString;
        while(file.hasNext())
        {
            clearString = file.next();
            System.out.println(clearString);
            clearString = clearString.replaceAll("time:","");
            fileContent.add(clearString);
        }

        //setp 2 输出文件内容
        //获取月份值
        ArrayList<Integer> fileContent2 = new ArrayList<Integer>();
        int amount = 0;
        String str;
        for(String timeData : fileContent)
        {

            str = timeData.split("-")[2];
            fileContent2.add(new Integer(str));
        }
        //setp 3
        //计算最大月份值
        int max_month = 0;
        Iterator<Integer> iterator = fileContent2.iterator();
        while (iterator.hasNext()){
            amount ++;
            int month = iterator.next();
            if(month > max_month){
                max_month = month;
            }
        }
        System.out.println("一共有"+amount+"条时间数据，最大月份为："+max_month);
    }
    }
